﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace awsomeSyntezator
{
	public partial class awsomeSyntezator : Form
	{
	    private List<float> gama;
	    public bool wygenerowano = false;
	    public SoundGalery galery;
	    public Options options = new Options();
		private bool libGeneruj = false;
		private bool libWczytaj = false;

		//wykres
		private const int GRAPHICWINDOW_WIDTH = 1150;
		private const int GRAPHICWINDOW_HEIGHT = 280;

		private const int GRAPHICWINDOW_X = 12;
		private const int GRAPHICWINDOW_Y = 446;
		private SolidBrush mBrushBlack, mBrushGrey;
		private int lastPressed = 0;
		public awsomeSyntezator()
		{
			InitializeComponent();
			fillOptions();
			windowStartup();
		}
        public void windowStartup()
        {
			SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
			mBrushBlack = new SolidBrush(Color.Black);
			mBrushGrey = new SolidBrush(Color.Green);

        	libGeneruj = true;
        	button2_Click(null, null);

            radioButton1.Checked = false;
            radioButton2.Checked = false;
			trackBar7.Enabled = false;
			trackBar8.Enabled = false;
			trackBar9.Enabled = false;

            //Generowanie dźwięku
            radioButton10.Checked = true; // odtwarzaj
            radioButton11.Checked = false; // na żywo

            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox1_CheckedChanged(null, null);
            checkBox2_CheckedChanged(null, null);
			//FadeIn by Default
        	radioButton12.Checked = true;
			//Default SINwawe Generator
        	radioButton3.Checked = true;

			harmonicsCheck00.Checked = true;
			harmonicsCheck01.Checked = false;
			harmonicsCheck02.Checked = false;
			harmonicsCheck03.Checked = false;
			harmonicsCheck04.Checked = false;
			harmonicsCheck05.Checked = false;

			harmonicsCheck00_CheckedChanged(null, null);
			harmonicsCheck01_CheckedChanged(null, null);
			harmonicsCheck02_CheckedChanged(null, null);
			harmonicsCheck03_CheckedChanged(null, null);
			harmonicsCheck04_CheckedChanged(null, null);
			harmonicsCheck05_CheckedChanged(null, null);

        	checkBox6.Checked = false;
			checkBox6_CheckedChanged(null, null);

			checkBox3.Checked = false;
			checkBox4.Checked = false;
			checkBox5.Checked = false;

			checkBox3_CheckedChanged(null, null);
			checkBox4_CheckedChanged(null, null);
			checkBox5_CheckedChanged(null, null);

			//wykres
			checkBox7.Checked = true;
			trackBar10_Scroll(null, null);

        }
	    public void fillOptions()
        {

			Options.harmonics.Add(1);
			for (int i = 0; i < 5; i++)
			{
				Options.harmonics.Add(0);
			}

			gama = new List<float>();
			gama.Add(261.6f);
			gama.Add(293.7f);
			gama.Add(329.6f);
			gama.Add(349.6f);
			gama.Add(391.9f);
			gama.Add(440.0f);
			gama.Add(493.9f);
			gama.Add(523.2f);

            Options.rate = 44100;
            Options.freq = 500;
            Options.time = 1000;

            Options.live = radioButton11.Checked;

	        Options.step = 1.0/Options.samples;

	    	Options.defaultOscilator = 0;
	    	Options.changed = true;

	    	Options.envelope = false;
	    	Options.fadeInOut = false;
	    	Options.envelopeStrengh = 1;
	    	Options.vibrato = false;
	        Options.vibratoFrequency = 1;
	    	Options.vibratoStrengh = 1;

        }

		private void OnPaint(object sender, PaintEventArgs e)
		{
			if (Options.changed && !checkBox7.Checked) return;
			e.Graphics.FillRectangle(mBrushBlack, GRAPHICWINDOW_X, GRAPHICWINDOW_Y, GRAPHICWINDOW_WIDTH, GRAPHICWINDOW_HEIGHT);

			short[] samples = galery.getSoundSamples(lastPressed);
			
			double scale = ((double)GRAPHICWINDOW_HEIGHT / Int16.MaxValue) / 2.0;
			int zeroHeigh = GRAPHICWINDOW_Y + GRAPHICWINDOW_HEIGHT/2;

			int start = Options.samples * trackBar11.Value / 100;
			int end = start + (Options.samples * trackBar10.Value/100);
			int step = (end - start)/GRAPHICWINDOW_WIDTH;
			GraphicsPath path = new GraphicsPath();

			for (int i = 0; i < GRAPHICWINDOW_WIDTH - 1; i++)
			{
				path.AddLine(i + GRAPHICWINDOW_X, (int)(samples[start + (i * step)] * scale + zeroHeigh), i + 1 + GRAPHICWINDOW_X, (int)(samples[start + ((i + 1)*step)] * scale + zeroHeigh));
			}
			e.Graphics.DrawLines(new Pen(mBrushGrey, 1), path.PathPoints);
			path.Reset();
		}
		public void awsomeSyntezator_KeyDown(object sender, KeyEventArgs e)
        {
            if (!wygenerowano)
            {
                MessageBox.Show(null, "Nie wybrałeś wybrałeś sposobu generowania dźwięków ", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
			if(Options.changed)
			{
				if (checkBox6.Checked)
				{
					bool harmonicFuckUp = true;
					for (int i = 0; i < Options.harmonics.Count; i++)
					{
						if (Options.harmonics[i] > 0)
						{
							harmonicFuckUp = false;
							break;
						}
					}
					if (harmonicFuckUp)
						Options.harmonics[0] = 1;
				}
				else
				{
					Options.harmonics[0] = 1;
					for (int i = 1; i <= 5; i++)
					{
						Options.harmonics[i] = 0;
					}
				}
				galery.generateGalery(gama);
				Options.changed = false;
				Invalidate();
			}
        	switch (e.KeyCode)
            {
				case Keys.Q: galery.playSound(0); lastPressed = 0; Invalidate(); break;
				case Keys.W: galery.playSound(1); lastPressed = 1; Invalidate(); break;
				case Keys.E: galery.playSound(2); lastPressed = 2; Invalidate(); break;
				case Keys.R: galery.playSound(3); lastPressed = 3; Invalidate(); break;
				case Keys.T: galery.playSound(4); lastPressed = 4; Invalidate(); break;
				case Keys.Y: galery.playSound(5); lastPressed = 5; Invalidate(); break;
				case Keys.U: galery.playSound(6); lastPressed = 6; Invalidate(); break;
				case Keys.I: galery.playSound(7); lastPressed = 7; Invalidate(); break; 
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if(libGeneruj == false)
            {
                libGeneruj = true;
                libWczytaj = false;
                radioButton2.Checked = false;
            }
            if(libGeneruj)
            {
                textBox1.Enabled = false;
                button2.Text = "Generuj";
            }
        }
        private void awsomeSyntezator_Load(object sender, EventArgs e)
        {

        }
        private void button1Click(object sender, EventArgs e)
        {
            textBox1.Enabled = true;
            radioButton2.Checked = true;
			OpenFileDialog fdlg = new OpenFileDialog
      	    {
      		    Title = "Otwórz plik XML",
      		    Filter = "Wszystkie pliki (*.*)|*.*|Pliki XML (*.xml)|*.xml",
      		    FilterIndex = 2,
      		    RestoreDirectory = true
      	    };
			if (fdlg.ShowDialog() != DialogResult.OK) return;

			textBox1.Text = fdlg.FileName;
            button2.Text = "Zaczytaj";
        }
        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (libWczytaj == false)
            {
                libGeneruj = false;
                libWczytaj = true;
                radioButton1.Checked = false;
            }
            if (libWczytaj)
            {
                textBox1.Enabled = true;
                button2.Text = "Zaczytaj";

            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if(libGeneruj)
            {
                galery = new SoundGalery(gama);
                wygenerowano = true;
            }
            else if (libWczytaj)
            {
                galery = new SoundGalery(textBox1.Text);
                wygenerowano = true;
            }
        }
        private void radioButton10_CheckedChanged(object sender, EventArgs e)
        {
            if(Options.live)
            {
                radioButton11.Checked = false;
                Options.live = false;
            }
        }
        private void radioButton11_CheckedChanged(object sender, EventArgs e)
        {
            if (!Options.live)
            {
                radioButton10.Checked = false;
                Options.live = true;
            }
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                groupBox9.Enabled = true;
            	Options.envelope = true;
				if(radioButton12.Checked)
				{
					Options.fadeInOut = false;
				}
				else
				{
					Options.fadeInOut = true;
				}
            	Options.envelopeStrengh = trackBar1.Value;
            }
            else
            {
                groupBox9.Enabled = false;
				Options.envelope = false;
			}
			Options.changed = true;
        }
        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                groupBox10.Enabled = true;
				Options.vibrato = true;
            }
            else
            {
            	Options.vibrato = false;
                groupBox10.Enabled = false;
			}
			Options.changed = true;
        }
        private void tBoxSamplingFreq_TextChanged(object sender, EventArgs e)
        {
            Options.rate = Convert.ToInt32(tBoxSamplingFreq.Text);
        	Options.changed = true;
        }
        private void tBoxSoundTime_TextChanged(object sender, EventArgs e)
        {
			Options.time = Convert.ToInt32(tBoxSoundTime.Text);
			Options.changed = true;
        }
        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
			Options.defaultOscilator = 0;
			Options.changed = true;
        }
		private void radioButton8_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 1;
			Options.changed = true;
		}
		private void radioButton7_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 2;
			Options.changed = true;
		}
		private void radioButton4_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 3;
			Options.changed = true;
		}
		private void radioButton5_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 4;
			Options.changed = true;
		}
		private void radioButton6_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 5;
			Options.changed = true;

            if (radioButton6.Checked)
            {
                trackBar7.Enabled = true;
            }
            else
            {
                trackBar7.Enabled = false;
                trackBar8.Enabled = false;
                trackBar9.Enabled = false;
            }
		}
		private void radioButton9_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 6;
			Options.changed = true;
		}
		private void radioButton16_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 7;
			Options.changed = true;
			if (radioButton16.Checked)
			{
				trackBar7.Enabled = true;
				trackBar8.Enabled = true;
				trackBar9.Enabled = true;
				trackBar7.Value = 50000;
				trackBar8.Value = 30;
				trackBar9.Value = 800;
				trackBar7_Scroll(null, null);
				trackBar8_Scroll(null, null);
				trackBar9_Scroll(null, null);
			}
			else
			{
				trackBar7.Enabled = false;
				trackBar8.Enabled = false;
				trackBar9.Enabled = false;
			}
		}
		private void radioButton15_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 8;
			Options.changed = true;
			if (radioButton15.Checked)
			{
				trackBar7.Enabled = true;
				trackBar8.Enabled = true;
				trackBar9.Enabled = true;
				label14.Text = @"Siła: ";
				label16.Text = @"Częst : ";
			}
			else
			{
				trackBar7.Enabled = false;
				trackBar8.Enabled = false;
				trackBar9.Enabled = false;
				label14.Text = @"Rezonans: ";
				label16.Text = @"Odcięcie: ";
			}
		}
		private void radioButton14_CheckedChanged(object sender, EventArgs e)
		{
			Options.defaultOscilator = 9;
			Options.changed = true;
			if (radioButton14.Checked)
			{
				trackBar7.Value = 437;
				trackBar8.Value = 41;
				trackBar9.Value = 891;
				trackBar7_Scroll(null, null);
				trackBar8_Scroll(null, null);
				trackBar9_Scroll(null, null);
				trackBar7.Enabled = true;
				trackBar8.Enabled = true;
				trackBar9.Enabled = true;
			}
			else
			{
				trackBar7.Enabled = false;
				trackBar8.Enabled = false;
				trackBar9.Enabled = false;
			}

		}
		private void radioButton12_CheckedChanged(object sender, EventArgs e)
		{
			Options.fadeInOut = false;
			Options.changed = true;
		}
		private void radioButton13_CheckedChanged(object sender, EventArgs e)
		{
			Options.fadeInOut = true;
			Options.changed = true;
		}
		private void trackBar1_Scroll(object sender, EventArgs e)
		{
			Options.envelopeStrengh = trackBar1.Value;
			label5.Text = trackBar1.Value.ToString();
			Options.changed = true;
		}
		private void trackBar2_Scroll(object sender, EventArgs e)
		{
			Options.vibratoStrengh = trackBar2.Maximum - trackBar2.Value;
			label6.Text = trackBar2.Value.ToString();
			Options.changed = true;
		}
		private void trackBar3_Scroll(object sender, EventArgs e)
		{
			Options.vibratoFrequency = trackBar3.Value;
			label8.Text = Options.vibratoFrequency.ToString();
			Options.changed = true;
		}
		private void harmonicsCheck00_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown00.Enabled = harmonicsCheck00.Checked;
			if (harmonicsCheck00.Checked)
				harmocicsUpDown00_ValueChanged(null, null);
			else
				Options.harmonics[0] = 0;
			Options.changed = true;
		}
		private void harmonicsCheck01_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown01.Enabled = harmonicsCheck01.Checked;
			if (harmonicsCheck01.Checked)
				harmocicsUpDown01_ValueChanged(null, null);
			else
				Options.harmonics[1] = 0;
			Options.changed = true;
		}
		private void harmonicsCheck02_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown02.Enabled = harmonicsCheck02.Checked;
			if (harmonicsCheck02.Checked)
				harmocicsUpDown02_ValueChanged(null, null);
			else
				Options.harmonics[2] = 0;
			Options.changed = true;
		}
		private void harmonicsCheck03_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown03.Enabled = harmonicsCheck03.Checked;
			if (harmonicsCheck03.Checked)
				harmocicsUpDown03_ValueChanged(null, null);
			else
				Options.harmonics[3] = 0;
			Options.changed = true;
		}
		private void harmonicsCheck04_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown04.Enabled = harmonicsCheck04.Checked;
			if (harmonicsCheck04.Checked)
				harmocicsUpDown04_ValueChanged(null, null);
			else
				Options.harmonics[4] = 0;
			Options.changed = true;
		}
		private void harmonicsCheck05_CheckedChanged(object sender, EventArgs e)
		{
			harmocicsUpDown05.Enabled = harmonicsCheck05.Checked;
			if (harmonicsCheck05.Checked)
				harmocicsUpDown05_ValueChanged(null, null);
			else
				Options.harmonics[5] = 0;
			Options.changed = true;
		}
		private void harmocicsUpDown00_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck00.Checked = true;
			Options.changed = true;
			Options.harmonics[0] = (int)harmocicsUpDown00.Value;
		}
		private void harmocicsUpDown01_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck01.Checked = true;
			Options.changed = true;
			Options.harmonics[1] = (int)harmocicsUpDown01.Value;
		}
		private void harmocicsUpDown02_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck02.Checked = true;
			Options.changed = true;
			Options.harmonics[2] = (int)harmocicsUpDown02.Value;
		}
		private void harmocicsUpDown03_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck03.Checked = true;
			Options.changed = true;
			Options.harmonics[3] = (int)harmocicsUpDown03.Value;
		}
		private void harmocicsUpDown04_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck04.Checked = true;
			Options.changed = true;
			Options.harmonics[4] = (int)harmocicsUpDown04.Value;
		}
		private void harmocicsUpDown05_ValueChanged(object sender, EventArgs e)
		{
			harmonicsCheck05.Checked = true;
			Options.changed = true;
			Options.harmonics[5] = (int)harmocicsUpDown05.Value;
		}
		private void checkBox6_CheckedChanged(object sender, EventArgs e)
		{
			if(checkBox6.Checked)
			{
				groupBox15.Enabled = true;
				groupBox16.Enabled = true;
				groupBox17.Enabled = true;
				groupBox18.Enabled = true;
				groupBox19.Enabled = true;
				groupBox20.Enabled = true;
			}
			else
			{
				groupBox15.Enabled = false;
				groupBox16.Enabled = false;
				groupBox17.Enabled = false;
				groupBox18.Enabled = false;
				groupBox19.Enabled = false;
				groupBox20.Enabled = false;
			}

			harmonicsCheck00_CheckedChanged(null, null);
			harmonicsCheck01_CheckedChanged(null, null);
			harmonicsCheck02_CheckedChanged(null, null);
			harmonicsCheck03_CheckedChanged(null, null);
			harmonicsCheck04_CheckedChanged(null, null);
			harmonicsCheck05_CheckedChanged(null, null);
		}
		private void checkBox3_CheckedChanged(object sender, EventArgs e)
		{
			if(checkBox3.Checked)
			{ 
				groupBox12.Enabled = true;
				Options.filter1 = true;

			}
			else
			{
				groupBox12.Enabled = false;
				Options.filter1 = false;
			}
			Options.changed = true;
		}
		private void checkBox4_CheckedChanged(object sender, EventArgs e)
		{
			if (checkBox4.Checked)
			{
				groupBox13.Enabled = true;
				Options.filter2 = true;

			}
			else
			{
				groupBox13.Enabled = false;
				Options.filter2 = false;
			}
			Options.changed = true;
		}
		private void checkBox5_CheckedChanged(object sender, EventArgs e)
		{
			if (checkBox5.Checked)
			{
				groupBox14.Enabled = true;
				Options.filter3 = true;

			}
			else
			{
				groupBox14.Enabled = false;
				Options.filter3 = false;
			}
			Options.changed = true;
		}
		private void trackBar4_Scroll(object sender, EventArgs e)
		{
			textBox2.Text = trackBar4.Value.ToString();
			Options.filter1freq = trackBar4.Value;
			Options.changed = true;
		}
		private void trackBar5_Scroll(object sender, EventArgs e)
		{
			textBox3.Text = trackBar5.Value.ToString();
			Options.filter2freq = trackBar5.Value;
			Options.changed = true;
		}
		private void trackBar6_Scroll(object sender, EventArgs e)
		{
			textBox4.Text = trackBar6.Value.ToString();
			Options.filter3freq = trackBar6.Value;
			Options.changed = true;
		}
		private void trackBar7_Scroll(object sender, EventArgs e)
		{
			Options.noiseDensity = trackBar7.Value;
			textBox5.Text = Options.noiseDensity.ToString();
			Options.changed = true;
		}
		private void trackBar8_Scroll(object sender, EventArgs e)
		{
			Options.effectResonance = trackBar8.Value;
			textBox6.Text = Options.effectResonance.ToString();
			Options.changed = true;
		}
		private void trackBar9_Scroll(object sender, EventArgs e)
		{
			Options.noiseEffectCutOffFrequency = trackBar9.Value;
			textBox7.Text = Options.noiseEffectCutOffFrequency.ToString();
			Options.changed = true;
		}
		private void textBox2_TextChanged(object sender, EventArgs e)
		{
			int freq = Convert.ToInt32(textBox2.Text);
			if (freq >= 32 && freq <= 22050)
			{
				trackBar4.Value = freq;
				Options.filter1freq = freq;
			}
			else if (freq < 20)
			{
				trackBar4.Value = 20;
				Options.filter1freq = 20;
			}
			else
			{
				trackBar4.Value = 22050;
				textBox2.Text = @"22050";
				Options.filter1freq = 22050;
			}
			Options.changed = true;
		}
		private void textBox3_TextChanged(object sender, EventArgs e)
		{
			int freq = Convert.ToInt32(textBox3.Text);
			if (freq >= 20 && freq <= 22050)
			{
				trackBar5.Value = freq;
				Options.filter1freq = freq;
			}
			else if (freq < 20)
			{
				trackBar5.Value = 20;
				Options.filter1freq = 20;
			}
			else
			{
				trackBar5.Value = 22050;
				textBox3.Text = "22050";
				Options.filter2freq = 22050;
			}
			Options.changed = true;
		}
		private void textBox4_TextChanged(object sender, EventArgs e)
		{
			int freq = Convert.ToInt32(textBox4.Text);
			if (freq >= 32 && freq <= 22050)
			{
				trackBar6.Value = freq;
				Options.filter1freq = freq;
			}
			else if (freq < 20)
			{
				trackBar6.Value = 20;
				Options.filter1freq = 20;
			}
			else
			{
				trackBar6.Value = 22050;
				textBox4.Text = @"22050";
				Options.filter3freq = 22050;
			}
			Options.changed = true;
		}
		private void numericUpDown1_ValueChanged(object sender, EventArgs e)
		{
			Options.changed = true;
			Options.filter1resonance = (int)numericUpDown1.Value;
		}
		private void numericUpDown2_ValueChanged(object sender, EventArgs e)
		{
			Options.changed = true;
			Options.filter2resonance = (int)numericUpDown2.Value;
		}
		private void numericUpDown3_ValueChanged(object sender, EventArgs e)
		{
			Options.changed = true;
			Options.filter3resonance = (int)numericUpDown3.Value;
		}
		private void radioButton18_CheckedChanged(object sender, EventArgs e)
		{
			Options.changed = true;
		}
		private void checkBox7_CheckedChanged(object sender, EventArgs e)
		{
			Options.changed = true;
			Invalidate();
		}
		private void trackBar10_Scroll(object sender, EventArgs e)
		{
			label18.Text = trackBar10.Value.ToString();
			trackBar11.Maximum = 100 - trackBar10.Value;
			Options.changed = true;
			Invalidate();
		}
		private void trackBar11_Scroll(object sender, EventArgs e)
		{
			int temp = trackBar11.Value;
			trackBar11.Maximum = 100 - trackBar10.Value;
			trackBar11.Value = Math.Min(temp, trackBar11.Maximum);
			Options.changed = true;
			Invalidate();
		}

		private void textBox5_TextChanged(object sender, EventArgs e)
		{
			int temp = Convert.ToInt32(textBox5.Text);
			if (temp >= trackBar7.Minimum && temp <= trackBar7.Maximum)
			{
				trackBar7.Value = temp;
				Options.noiseDensity = trackBar7.Value;
			}
			else if (temp < 20)
			{
				trackBar7.Value = trackBar7.Minimum;
				Options.noiseDensity = trackBar7.Value;
			}
			else
			{
				trackBar7.Value = trackBar7.Maximum;
				textBox5.Text = trackBar7.Maximum.ToString();
				Options.noiseDensity = trackBar7.Value;
			}
			Options.changed = true;
		}

		private void textBox6_TextChanged(object sender, EventArgs e)
		{
			int temp = Convert.ToInt32(textBox6.Text);
			if (temp >= trackBar8.Minimum && temp <= trackBar8.Maximum)
			{
				trackBar8.Value = temp;
				Options.effectResonance = trackBar8.Value;
			}
			else if (temp < trackBar8.Minimum)
			{
				trackBar8.Value = trackBar8.Minimum;
				Options.effectResonance = trackBar8.Value;
			}
			else
			{
				trackBar8.Value = trackBar8.Maximum;
				textBox6.Text = trackBar8.Maximum.ToString();
				Options.effectResonance = trackBar8.Value;
			}
			Options.changed = true;
		}

		private void textBox7_TextChanged(object sender, EventArgs e)
		{
			int temp = Convert.ToInt32(textBox7.Text);
			if (temp >= trackBar9.Minimum && temp <= trackBar9.Maximum)
			{
				trackBar9.Value = temp;
				Options.noiseEffectCutOffFrequency = trackBar9.Value;
			}
			else if (temp < trackBar9.Minimum)
			{
				trackBar9.Value = trackBar9.Minimum;
				Options.noiseEffectCutOffFrequency = trackBar9.Value;
			}
			else
			{
				trackBar9.Value = trackBar9.Maximum;
				textBox7.Text = trackBar9.Maximum.ToString();
				Options.noiseEffectCutOffFrequency = trackBar9.Value;
			}
			Options.changed = true;
		}
	}
}
